import Vue from 'vue'
import VueRouter from 'vue-router'
import HomeView from '../views/HomeView.vue'
import IndexView from '../views/IndexView.vue'
import NotFoundView from '../views/NotFoundView.vue'
import ArticleView from '../views/ArticleView.vue'
import MoodView from '../views/MoodView.vue'
import PicView from '../views/PicView.vue'
import ProjectView from '../views/ProjectView.vue'
import WebsView from '../views/WebsView.vue'
import MoodPageView from '../views/MoodPageView.vue'

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    name: 'index',
    component: IndexView
  },
  {
    path:'/?page=:page',
    name:'index_page',
    component: IndexView
  },
  {
    path: '/vue',
    name: 'home',
    component: HomeView
  },
  {
    path: '/about',
    name: 'about',
    // route level code-splitting
    // this generates a separate chunk (about.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    component: () => import(/* webpackChunkName: "about" */ '../views/AboutView.vue')
  },{
    path: '*',
    name: '/404',
    component: NotFoundView
  },
  {
    path: '/index',
    redirect: '/'
  },
  {
    path: '/article/:id',
    name:'article',
    component: ArticleView,
    props : true
  },
  {
    path: '/mood',
    name:'mood',
    component: MoodView
  },
  {
    path: '/mood/:id',
    name:'moodpage',
    component:MoodPageView
  },
  {
    path: '/pic',
    name:'pic',
    component: PicView
  },
  {
    path: '/project',
    name:'project',
    component: ProjectView
  },
  {
    path: '/webs',
    name:'webs',
    component: WebsView
  },
]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})

export default router

router.beforeEach((to, from, next) => {
  document.body.scrollTop = 0;
  document.documentElement.scrollTop = 0;

  // 兼容IE
  window.scrollTo(0, 0);
  next();

  const isLogin = localStorage.eleToken ? true : false
})
